package br.com.rampage.controller.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.rampage.model.bean.UnidadeSaude;
import br.com.rampage.model.bo.VacinaBO;
import br.com.rampage.utils.AppUtils;
import br.com.rampage.utils.ConnectionUsersUtil;

/**
 * Servlet implementation class CadastroVacinaServlet
 */
@WebServlet("/CadastroVacinaServlet")
public class CadastroVacinaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CadastroVacinaServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String nome = request.getParameter("nome");
		String dataFabricacao = request.getParameter("dataFabricacao");
		String dataVencimento = request.getParameter("dataVencimento");
		
		
		

		boolean success = new VacinaBO().cadastrar(nome, dataFabricacao,
				dataVencimento);

		if (success) {
			response.setContentType("text/html;charset-UTF-8");
			PrintWriter writer = response.getWriter();
			new Message().print(writer, TypeReturnServlet.success,
					"Vacina cadastrada com sucesso!");

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/cadastro_vacina.jsp");
			dispatcher.include(request, response);
		} else {

			response.setContentType("text/html;charset-UTF-8");
			PrintWriter writer = response.getWriter();
			new Message().print(writer, TypeReturnServlet.danger,
					"Login/Senha incorreto!");

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/cadastro_vacina.jsp");
			dispatcher.include(request, response);
			;
		}
	}

}
